package com.Homework2;

import java.util.*;

public class Test06 {
    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();
        System.out.println("请输入字符串");
        String s = new Scanner(System.in).nextLine();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if ((chars[i] <= 'z' && chars[i] >= 'a') || (chars[i] <= 'Z' && chars[i] >= 'A')) {
                countingKey(map, "字母");
            } else if ('9' >= chars[i] && chars[i] >= '0') {
                countingKey(map, "数字");
            } else if (' ' == chars[i]) {
                countingKey(map, "空格");
            } else {
                countingKey(map, "其他");
            }
        }
        Set<String> strings = map.keySet();
        for (String key : strings) {
            System.out.println(key + "=" + map.get(key));
        }
    }

    private static void countingKey(HashMap<String, Integer> map,String key) {
       if(map.get(key)==null){
           map.put(key,1);
       }else {
           int integer = map.get(key);
           map.put(key,++integer);
       }
    }
}
